package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.model.request.UpdateLabelRequest;
import com.ytjj.qmyx.admin.service.BankerLabelService;
import com.ytjj.qmyx.admin.utils.UserUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * 
 * @Version: 1.0
 */
@RestController
@RequestMapping("/bankerLabel")
public class BankerLabelController {

    @Resource
    private BankerLabelService bankerLabelService;


    /**
     *  分页查询
     * @param bankerLabelName 标签名
     * @param pageNum 页码
     * @param pageSize 数量
     * @return CommonResult
     */
    @GetMapping("/select")
    public CommonResult select(@RequestParam(value = "bankerLabelName", required = false) String bankerLabelName,
                               @RequestParam(value = "pageNum", defaultValue = "1", required = false)Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10", required = false)Integer pageSize) {
        return CommonResult.success(bankerLabelService.newSelect(bankerLabelName,pageNum,pageSize));
    }

    /**
     * 增加修改标签
     * @param bankerLabelName 名
     * @param bankerLabelId id
     * @return CommonResult
     */
    @GetMapping("/addAndUpdate")
    public String addAndUpdate(@RequestParam(value = "bankerLabelName") String bankerLabelName,
                                     @RequestParam(value = "bankerLabelId",required = false) Integer bankerLabelId,
                                     @RequestParam(value = "colour") String colour) {
        Integer adminId = UserUtil.getAdminId();
        return bankerLabelService.newAddAndUpdate(bankerLabelName,bankerLabelId,adminId,colour);
//        return bankerLabelService.addAndUpdate(bankerLabelName,bankerLabelId,adminId,colour);
    }


    /**
     *  删除标签
     * @param bankerLabelId 标签id
     * @return CommonResult
     */
    @GetMapping("/delete")
    public String delete(@RequestParam(value = "bankerLabelId") Integer bankerLabelId) {
        return bankerLabelService.newDelete(bankerLabelId);
//        return bankerLabelService.delete(bankerLabelId);
    }

    /**
     *  查询所有标签
     * @return CommonResult
     */
    @GetMapping("/selectAll")
    public String selectAll() {
        return bankerLabelService.selectAll();
    }

    /**
     * 新增供应商 关联 标签 的数据
     * @return
     */
    @PostMapping("/addBankerLabel")
    public String addBankerLabel(@RequestBody UpdateLabelRequest updateLabelRequest) {
        Integer adminId = UserUtil.getAdminId();
        updateLabelRequest.setAdminId(adminId);
        return bankerLabelService.newAddBankerLabel(updateLabelRequest);
//        return bankerLabelService.addBankerLabel(updateLabelRequest.getBankerIds(),updateLabelRequest.getBankerLabelIds(),adminId);
    }
}
